package com.woniuxy.controller;

import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.impl.ReadingQuServiceImpl;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/readingQu")
public class ReadingQuController {

    @Autowired
    private ReadingQuServiceImpl readingQuService;

    @GetMapping("loadAll")
    public ResponseEntity loadAll(){
        Map<Object, Object> allReadingQu = readingQuService.findAllReadingQu();
        return new ResponseEntity(allReadingQu);
    }

    @PostMapping("/addReadingQu")
    public ResponseEntity addReadingQu(@RequestBody Map<String, Object> param){
        return readingQuService.addReadingQu(param);
    }

    @GetMapping("findAllInfo/{id}")
    @ApiOperation(value = "根据id找到所有阅读题")
    @ApiResponses({
            @ApiResponse(code = 0, message = "加载成功"),
            @ApiResponse(code = 1, message = "加载失败")
    })
    public ResponseEntity findAllSubject(
            @ApiParam(value = "入参Id", example = "")
            @PathVariable Integer id){
        Map<String, Object> allInfo = readingQuService.findAllInfo(id);
        return new ResponseEntity(allInfo);
    }

}
